package com.helloandroid.dialogs

import android.content.Intent
import android.view.View
import android.widget.TextView
import com.helloandroid.R
import com.helloandroid.base.BaseDialogFragment
import com.helloandroid.view.MySpannableString
import com.protol.PrivacyPolicyActivity
import com.protol.ProtocolActivity
import com.protol.TermsActivity

class YinSiDialog: BaseDialogFragment() {

    lateinit var tvDesc:TextView
    override fun initViews(view: View) {
        tvDesc = findViewById(R.id.tvDesc)
        val content = MySpannableString(
                requireContext(),
                "查看完整版《服务协议》及《隐私政策》")
                .first("《服务协议》")
                .textColor(R.color.dd_main_blue)
                .onClick(tvDesc){
                    showXieYi()
                }
                .first("《隐私政策》")
                .textColor(R.color.dd_main_blue)
                .onClick(tvDesc){
                    showTiaoKuan()
                }
        tvDesc.text = content

        val activity = requireActivity() as ProtocolActivity
        findBtn(R.id.btnNo).setOnClickListener {
            dismiss()
            activity.finish()
        }
        findBtn(R.id.btnYes).setOnClickListener {
            dismiss()
            activity.hanldeRuntimePermission()
        }
    }

    override fun initData() {
    }

    override fun getContentViewResId(): Int = R.layout.dialog_yinsi

    override fun dialogTag(): String {
        return "yinsi"
    }

    private fun  showXieYi(){
        val activity = requireActivity();
        activity.startActivity(Intent(activity, TermsActivity::class.java))
    }

    private fun showTiaoKuan(){
        val activity = requireActivity();
        activity.startActivity(Intent(activity, PrivacyPolicyActivity::class.java))
    }
}